package com.hzpd.hainan.utils;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created by 猪猪侠 on 2017/7/3.
 */

public class ParamUtils {
    public static Map<String, String> getRequestParam(Map<String, String> map) {
        Iterator iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            if (entry.getValue() == null || StringUtils.isNull(entry.getValue().toString())) {
                entry.setValue("");
            }
            if (StringUtils.isContainsChinese(entry.getValue().toString())) {
                try {
                    entry.setValue(URLEncoder.encode(entry.getValue().toString(), "UTF-8"));
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
        }
        Map<String, String> sortMap = sortMapByKey(map);
        return sortMap;
    }
    private static Map<String, String> sortMapByKey(Map<String, String> map) {
        if (map == null || map.isEmpty()) {
            return null;
        }
        return map;
    }
}
